package com.xnyzc.lhy.order.controller.dapi.driver;

import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.service.work.IOaDWorkTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description
 * @Author Bin
 * @Date 2019/8/3 16:13
 **/
@RestController
@RequestMapping(value = "dapi/driverWorkTime")
public class DriverWorkTimeController {

    @Autowired
    private IOaDWorkTimeService iOaDWorkTimeService;

    /**
     * 获取在线时长
     * @return
     */
    @GetMapping(value = "getWorkTime")
    public Map<String, Object> getWorkTime(){
        Long driverId = TokenUtil.getTokenUserId();
        if (driverId == null){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.strIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return iOaDWorkTimeService.getWorkTime(driverId, tag);
    }
}
